﻿@model HmPMer.Entity.UserBaseInfo
@{
    Layout = "~/Views/Shared/_Content.cshtml";
    var adminlist = new HmPMer.Business.AccountBll().GetAllHmAdmin();
    var gradelist = new HmPMer.Business.GradeBll().GetAllUserGrade(0);
    var wsList = new HmPMer.Business.WithdrawBll().GetAllWithdrawSchemeList(0);
    var agentList = new HmPMer.Business.UserBaseBll().GetUserBaseForType(2);
}

<form class="layui-form" id="formData" style="width:80%;">
    <br />
    <div class="layui-row">
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">商户Id</label>
            <div class="layui-input-block">
                @Html.Hidden("UserId", Model.UserId)
                <input type="text" class="layui-input" lay-verify="required" name="UserId" style="border:none" readonly value="@Model.UserId">
            </div>
        </div>
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">商户名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" lay-verify="required" placeholder="请输入商户名" id="MerName" name="MerName" value="@Model.MerName">
            </div>
        </div>

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">所属业务员</label>
            <div class="layui-input-block">
                <select name="PromId" class="PromId" lay-filter="PromId">
                    <option value="">请选择管理员</option>
                    @foreach (var item in adminlist)
                    {
                        <option value="@item.ID" @(item.ID == Model.PromId ? "selected" : "")>@item.NickName</option>
                    }
                </select>
            </div>
        </div>

    </div>

    <div class="layui-row">
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">商户类型</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" lay-verify="required" name="AccountType" style="border:none" readonly value=" @(Model.AccountType == 0 ? "个人" : "企业")">               
            </div>
        </div>
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">商户等级</label>
            <div class="layui-input-block">
                <select name="GradeId" class="GradeId" lay-filter="GradeId">
                    <option value="0">请选择等级</option>
                    @foreach (var item in gradelist)
                    {
                        <option value="@item.Id" @(Model.GradeId == item.Id ? "selected" : "")>@item.GradeName</option>
                    }
                </select>
            </div>
        </div>

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">所属代理</label>
            <div class="layui-input-block">
                <select name="AgentId" class="AgentId" lay-filter="AgentId">
                    <option value="">请选择代理</option>
                    @foreach (var item in agentList)
                    {
                        <option value="@item.UserId" @(item.UserId == Model.AgentId ? "selected" : "")>@item.MerName</option>
                    }
                </select>
            </div>
        </div>

    </div>

    <div class="layui-row">
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">结算方案</label>
            <div class="layui-input-block">
                <select name="WithdrawSchemeId" class="WithdrawSchemeId" lay-filter="WithdrawSchemeId">
                    <option value="0">请选择结算方案</option>
                    @foreach (var item in wsList)
                    {
                        <option value="@item.Id" @(Model.WithdrawSchemeId == item.Id ? "selected" : "")>@item.SchemeName</option>
                    }
                </select>
            </div>
        </div>
    </div>


    <div class="layui-row">
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">手机</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="MobilePhone" onkeyup="this.value=this.value.replace(/[^\d{1-9}{1}\d{0-9}]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d{1-9}{1}\d{0-9}]/g,'')" placeholder="请输入手机" value="@Model.MobilePhone">
            </div>
        </div>
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">QQ</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="QQ" placeholder="请输入QQ号" value="@Model.QQ">
            </div>
        </div>

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="Email" placeholder="请输入Email号" value="@Model.Email">
            </div>
        </div>

    </div>


    @*<div class="layui-row">
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">身份证姓名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="FactName" placeholder="请输入身份姓名" value="@Model.FactName">
            </div>
        </div>
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="IdCard" placeholder="请输入身份证号" value="@Model.IdCard">
            </div>
        </div>
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="Email" placeholder="请输入Email号" value="@Model.Email">
            </div>
        </div>
    </div>*@

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">认证信息</label>
        <div class="layui-input-block">
            @Html.Hidden("IsMobilePhone", Model.IsMobilePhone)
            @*@Html.Hidden("IsIdCard", Model.IsIdCard)*@
            @Html.Hidden("IsEmail", Model.IsEmail)
            <input type="checkbox" lay-filter="cbkmoblie" name="" title="手机" @(Model.IsMobilePhone == 1 ? "checked" : "")>
            @*<input type="checkbox" lay-filter="cbkcard" name="" title="实名" @(Model.IsIdCard == 1 ? "checked" : "")>*@
            <input type="checkbox" lay-filter="cbkemail" name="" title="邮箱" @(Model.IsEmail == 1 ? "checked" : "")>
        </div>
    </div>

    <div class="layui-row">
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" name="Pass" placeholder="" value="">
            </div>
        </div>
        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">二级密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" name="Pass2" placeholder="" value="">
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">商户密钥</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="ApiKey" name="ApiKey" placeholder="请输入ApiKey" value="@Model.ApiKey" style="border:none;float:left;width:300px;" readonly>
            <button type="button" class="layui-btn layui-btn-sm" id="btn_rest_apikey" style="float:left">重置密钥</button>
        </div>
    </div>


    <div class="layui-row">

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">注册时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input userEmail" readonly style="border:none" value="@Model.RegTime.Value.ToString("yyyy-MM-dd HH:mm")" name="RegTime">
            </div>
        </div>

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">注册Ip</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" readonly style="border:none" value="@Model.RegIp" />
            </div>
        </div>


    </div>


    <div class="layui-row">

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">最后登录</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" readonly style="border:none" value="@Model.LastLoginTime.Value.ToString("yyyy-MM-dd HH:mm")" />
            </div>
        </div>

        <div class="magb15 layui-col-md4 layui-col-xs12">
            <label class="layui-form-label">最后登录Ip</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" readonly style="border:none" value="@Model.LastLoginIp" />
            </div>
        </div>

    </div>


    <div class="layui-form-item layui-row layui-col-xs12" style="text-align:center">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-sm" id="btn_update_sub">保存</button>
        </div>
    </div>
</form>

<script>

    layui.use(['hm', 'form', 'layer', 'laydate', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            hm = layui.hm;

        form.on('checkbox(cbkmoblie)', function (data) {
            if (data.elem.checked) {
                $("#IsMobilePhone").val(1);
            } else {
                $("#IsMobilePhone").val(0);
            }
            form.render('checkbox');
        });

        //form.on('checkbox(cbkcard)', function (data) {
        //    if (data.elem.checked) {
        //        $("#IsIdCard").val(1);
        //    } else {
        //        $("#IsIdCard").val(0);
        //    }
        //    form.render('checkbox');

        //});

        form.on('checkbox(cbkemail)', function (data) {
            if (data.elem.checked) {
                $("#IsEmail").val(1);
            } else {
                $("#IsEmail").val(0);
            }
            form.render('checkbox');

        });

        $("#btn_rest_apikey").click(function () {
            
            $("#ApiKey").val('@(HM.Framework.EncryUtils.MD5(Guid.NewGuid().ToString()))');
        });

        //提交数据
        $("#btn_update_sub").click(function () {
            var MerName = $("#MerName").val();

            if (!MerName || MerName == "") {
                layer.msg("请输入商户名称！");
                return;
            }

            var index = layer.msg('修改中，请稍候', { icon: 16, time: false, shade: 0.8 });
            setTimeout(function () {
                layer.close(index);
                hm.ajax("/Business/BusinessUpdateInfo", {
                    data: {
                        Model: hm.serializeObject($("#formData"))
                    },
                    type: "POST",
                    dataType: 'json',
                    success: function (result) {
                        if (result.Success) {
                            layer.msg("操作成功！", { icon: 1, time: 300, });
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.tableIns.reload();
                            parent.layer.close(index);
                        } else {
                            layer.msg(result.Message);
                        }
                    },
                    error: function (x, t, e) {
                        layer.closeAll();
                    }
                });

            }, 500);

        });

    })
</script>

